package laboratoryQ.ui.draw;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

import laboratoryQ.ui.draw.style.IStylizer;

public class SieveDrawer implements IDrawer {
	public static final SieveDrawer WHITE_INSTANCE = new SieveDrawer(Color.WHITE, new int[] {2, 3});
	private Color color;
	private int[] period;

	public SieveDrawer(Color color, int[] period) {
		this.color = color;
		this.period = period;
	}
	
	@Override
	public void draw(Graphics g, IStylizer stylizer) {
		g.setColor(color);
		Rectangle b = g.getClipBounds();
		int length = Math.max(b.height, b.width);
		
		boolean draw = true;
		int pos = 0;
		int remaind = period[pos];
		pos = (pos + 1) % period.length;
		for (int i = 0; i < length * 2; i++) {
			if (draw) {
				g.drawLine(0, i, length, i - length);
			}
			remaind--;
			if (remaind <= 0) {
				draw = !draw;
				remaind = period[pos];
				pos = (pos + 1) % period.length;
			}
		}
	}
}
